<template>
  <div id="Dodecahedron"></div>
</template>

<script setup lang="ts">
import { onMounted, render } from 'vue'
import * as THREE from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'

const scene = new THREE.Scene()
const geometry = new THREE.DodecahedronGeometry(10, 1)
const solideMaterial = new THREE.MeshBasicMaterial({
    color: '#2b7098',
    transparent: true,
    opacity: 0.8
})
const humbelMaterial = new THREE.MeshBasicMaterial({
    color: 'white',
    wireframe: true
})

const solideMesh = new THREE.Mesh(geometry, solideMaterial)
const humbelMesh = new THREE.Mesh(geometry, humbelMaterial)
scene.add(solideMesh)
scene.add(humbelMesh)

const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)
camera.position.z = 100

const renderer = new THREE.WebGLRenderer(camera, solideMesh)
renderer.setSize(window.innerWidth, window.innerHeight)

const animate = () => {
    requestAnimationFrame(animate)
    solideMesh.rotation.x += 0.01
    solideMesh.rotation.y += 0.01
    solideMesh.rotation.z += 0.01
    humbelMesh.rotation.x += 0.01
    humbelMesh.rotation.y += 0.01
    humbelMesh.rotation.z += 0.01
    renderer.render(scene, camera)
}

onMounted(() => {
    new OrbitControls(camera, renderer.domElement)
    document.getElementById('Dodecahedron')?.appendChild(renderer.domElement)
    animate()
})

window.onresize = () => {
    renderer.setSize(window.innerWidth, window.innerHeight)
    camera.aspect = window.innerWidth / window.innerHeight
    camera.updateProjectionMatrix()
}
</script>

<style>

</style>